package com.zhuzhe.blog.system.controller;


import com.zhuzhe.blog.base.JsonData;
import com.zhuzhe.blog.base.ResponseData;
import com.zhuzhe.blog.convert.Convert;
import com.zhuzhe.blog.system.entity.SysMenu;
import com.zhuzhe.blog.system.requestDto.SysMenuDto;
import com.zhuzhe.blog.system.responseVo.SysMenuListVo;
import com.zhuzhe.blog.system.service.ISysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 菜单信息表 前端控制器
 * </p>
 *
 * @author u53
 * @since 2020-10-13
 */
@Api(value = "菜单管理接口",description = "提供菜单的增删改查接口")
@RestController
@RequestMapping("/sys-menu")
public class SysMenuController {


    @Autowired
    private ISysMenuService sysMenuService;

    @PostMapping("/seach")
    @ApiOperation("根据菜单名称查询列表接口")
    public ResponseData<SysMenuListVo> seachMenu(@RequestBody SysMenuDto sysMenuDto){
        return sysMenuService.queryList(sysMenuDto);
    }


    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据菜单id删除菜单及子菜单")
    @ApiImplicitParam(name = "id",value = "菜单id",required  = true)
    public ResponseData<Integer> deleteMenu(@PathVariable("id") String id){
        return sysMenuService.deleteById(id);
    }


    @PostMapping("/save")
    @ApiOperation("新增菜单信息接口")
    public ResponseData<Integer> save(@RequestBody SysMenuDto sysMenuDto){
        SysMenu sysMenu = new SysMenu();
        Convert.convertType(sysMenuDto,sysMenu);
        return JsonData.success(sysMenuService.save(sysMenu)) ;
    }


    @GetMapping("/view/{id}")
    @ApiOperation("查询菜单详情接口")
    @ApiImplicitParam(name = "id",value = "菜单id",required = true)
    public ResponseData<SysMenu> viewMenu(@PathVariable("id") String id){
        return sysMenuService.viewMenu(id);
    }

    @PutMapping("/update")
    @ApiOperation("修改菜单信息接口")
    @ApiImplicitParam(name = "sysMenuDto",value = "菜单信息",required = true)
    public ResponseData<Integer> updateMenu(@RequestBody SysMenuDto sysMenuDto){
        return sysMenuService.updateMenu(sysMenuDto);
    }

}
